local skel = fk.CreateSkill {
  name = "efengqi__wangxi",
}

Fk:loadTranslationTable{
  ["efengqi__wangxi"] = "忘隙",
  [":efengqi__wangxi"] = "每回合各限一次，当你对其他角色造成或受到其他角色造成的伤害后，可以摸两张牌并交给对方一张牌；当你进入濒死状态时，"..
  "此技能视为未发动。",

  ["#efengqi__wangxi-ask"] = "忘隙：可以摸两张牌并交给 %src 一张牌",
  ["#efengqi__wangxi-give"] = "忘隙：请交给 %src 一张牌。",

  ["$efengqi__wangxi1"] = "大丈夫，何拘小节。",
  ["$efengqi__wangxi2"] = "前尘往事，莫再提起。",
}

skel:addEffect(fk.Damage, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name)
    and data.to and not data.to.dead and player ~= data.to
    and not table.contains(player:getTableMark("efengqi__wangxi-turn"), 1)
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#efengqi__wangxi-ask:"..data.to.id }) then
      event:setCostData(self, {tos = {data.to} })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addTableMark(player, "efengqi__wangxi-turn", 1)
    local to = data.to
    player:drawCards(2, skel.name)
    if not player.dead and not player:isNude() and to and not to.dead and to ~= player then
      local card = room:askToCards(player, { min_num = 1, max_num = 1, include_equip = true,
      skill_name =  skel.name, cancelable = false, prompt = "#efengqi__wangxi-give:"..to.id })
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerHand, to, fk.ReasonGive, skel.name, nil, false, player)
      end
    end
  end,
})

skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name)
    and data.from and not data.from.dead and data.from ~= player
    and not table.contains(player:getTableMark("efengqi__wangxi-turn"), 2)
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#efengqi__wangxi-ask:"..data.from.id }) then
      event:setCostData(self, {tos = {data.from} })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addTableMark(player, "efengqi__wangxi-turn", 2)
    local to = data.from
    player:drawCards(2, skel.name)
    if not player.dead and not player:isNude() and to and not to.dead and to ~= player then
      local card = room:askToCards(player, { min_num = 1, max_num = 1, include_equip = true,
      skill_name =  skel.name, cancelable = false, prompt = "#efengqi__wangxi-give:"..to.id })
      if #card > 0 then
        room:moveCardTo(card, Card.PlayerHand, to, fk.ReasonGive, skel.name, nil, false, player)
      end
    end
  end,
})

skel:addEffect(fk.EnterDying, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("efengqi__wangxi-turn") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "efengqi__wangxi-turn", 0)
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "efengqi__wangxi-turn", 0)
end)

return skel
